package com.zadtek.shopmall.base;

/**
 * Created by Zackv on 2018/4/2.
 */

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Window;
import android.view.WindowManager;

import com.bumptech.glide.Glide;
import com.zadtek.shopmall.R;
import com.zadtek.shopmall.net.BaseObserver;
import com.zadtek.shopmall.view.dialog.BaseNiceDialog;
import com.zadtek.shopmall.view.dialog.NiceDialog;

import org.greenrobot.eventbus.EventBus;


public abstract class AbsActivity extends BaseActivity implements BaseObserver.DialogHelper{

    protected Activity mActivity;
    private BaseNiceDialog niceDialog;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        mActivity = this;
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏

        if (fullScreen()) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
                    , WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }

        overridePendingTransition(R.anim.push_pic_left_in, R.anim.push_pic_left_out);
        final int vid = setView();

        super.onCreate(savedInstanceState);

        if (vid != 0) {
            setContentView(vid);
            initBasic(savedInstanceState);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        Glide.with(this).pauseRequestsRecursive();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Glide.with(this).resumeRequestsRecursive();
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.push_pic_right_in, R.anim.push_pic_right_out);
    }

    /**
     * 是否全屏
     *
     * @return true则全屏
     */
    public boolean fullScreen() {
        return false;
    }

    /**
     * 关联主界面
     */
    public abstract int setView();

    /**
     * 基础初始化
     */
    public abstract void initBasic(Bundle savedInstanceState);

    public void showLoadingProgress() {
        if (niceDialog == null) {
            niceDialog = NiceDialog.init()
                    .setLayoutId(R.layout.loading)
                    .setWidth(100)
                    .setHeight(100)
                    .setDimAmount(0)
                    .setOutCancel(false)
                    .show(getSupportFragmentManager());
        }
    }

    public void dismissLoadingProgress() {
        if(niceDialog!=null){
            niceDialog.dismiss();
            niceDialog = null;
        }
    }

    @Override
    public void showRetryView() {
    }
}

